import request from '@/utils/request.js'

// 封装登录接口
export const userLoginService = (LoginData) => {
    // 使用UrlSearchParams 将对象转换为查询字符串，如果不转换默认是json格式
    const params = new URLSearchParams();
    for(let key in LoginData){
        params.append(key, LoginData[key]);
    }
    return request.post('/user/login', params);
}

// 查询用户信息
export const userInfoService = () => {
    return request.get('/user/info');
}

// 查询用户列表
export const userListService = (params) => {
    return request.get('/user/list',{params: params});
}

// 添加用户
export const addUserService = (data) => {
    return request.post('/user/add', data);
}

// 修改用户
export const updateUserService = (data) => {
    return request.put('/user/update', data);
}

// 删除用户
export const deleteUserService = (id) => {
    return request.delete(`/user/delete/${id}`);
}

// 更新数据库头像信息
export const uploadAvatarService = (avatarUrl) => {
    // 使用UrlSearchParams 将对象转换为查询字符串
    const params = new URLSearchParams();
    params.append('avatarUrl', avatarUrl);
    return request.patch('/user/updateAvatar', params);
}

// 修改密码
export const updatePasswordService = (data) => {
    return request.put('/user/updatePwd', data);
}

// 批量删除
export const batchDeleteUserService = (data) => {
    return request.delete('/user/batchDelete', {data: data});
}